<?php
class Komentar extends CI_Model{
	
	function get_current_komentar($jenis, $id, $tipe = NULL, $id_komentar=NULL){
		if($tipe != 'LIST_KOMENTAR'){
			$this->db->select('komentar.*, alumni.nama as comment_writer, alumni.foto as avatars_comment_writer');
		}else{
			$this->db->select('COUNT(komentar.id_komentar) as total_komentar, komentar.*, alumni.nama as comment_writer, '.$jenis.'.*, alumni.foto as avatars_comment_writer');
		}
		$this->db->from('komentar');
		$this->db->join($jenis, $jenis.'.id_'.$jenis."=komentar.id_item");
		$this->db->join('alumni','alumni.id_user=komentar.id_user');
		$this->db->where('komentar.jenis', $jenis);
		$this->db->where('komentar.id_item', $id);
		if($id_komentar){
			$this->db->where('komentar.id_komentar', $id_komentar);
		}
		$this->db->order_by("komentar.id_komentar", "desc"); 
		$query = $this->db->get();
		return $query->result_array();		
	}
	
	function add($data){
		$this->db->insert('komentar',$data);
		return $this->db->insert_id();
	}
	
	function delete($item_id){
		$this->db->delete('komentar', array('id_item' => $item_id)); 
	}
}
?>